package com.yyy.test.rxjavatest;

import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.Subscriber;
import rx.functions.Action1;
import rx.functions.Func1;

/**
 * Hello world!
 *
 */
public class App {
    public static void main(String[] args) {
        //test1();
        test2();
    }
    private static void test1() {
        String[] array = {"hello", "rxJava"};
        Observable<String> observable = Observable.from(array);
        observable.map(new Func1<String, String>() {
            public String call(String str) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                }
                System.out.println("str=====" + str);
                return str + "deal";
            }
        }).subscribe(new Subscriber<String>() {
            public void onCompleted() {
            }
            public void onError(Throwable arg0) {
            }
            public void onNext(String arg0) {
                System.out.println(arg0);
            }
        });
        observable.flatMap(new Func1<String, Observable<String>>() {
            public Observable<String> call(String arg0) {
                System.out.println(arg0 + "---");
                return Observable.just(arg0);
            }
        }).subscribe(new Action1<String>() {
            public void call(String arg0) {
                System.out.println(arg0);
            }
        });
    }
    public static void test2() {
        Observable.just("原味的Observable").flatMap(new Func1<String, Observable<?>>() {
            @Override
            public Observable<?> call(String s) {
                return Observable.just("加孜然了的" + s);
            }
        }).subscribe(new Action1<Object>() {
            @Override
            public void call(Object o) {
                System.out.println(o.toString());
            }
        });
    }
}
